package com.qiaofang.repository;

import com.qiaofang.entity.Company;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CompanyRepository extends JpaRepository<Company, Long>, JpaSpecificationExecutor {

    @Query(nativeQuery = true, value = "select c.company_code from tm_company c where c.company_code like :company_code order by c.company_code desc limit 1 ")
    String getMaxCompanyCode(@Param(value = "company_code") String pro);

    @Query(nativeQuery = true, value = "select c.id ,c.company_name from tm_company c where c.company_type = :company_type and del_flag = 0 order by create_time desc")
    List<Object[]> listOptionCompany(@Param(value = "company_type") Long type);

    /**
     * 通过公司uuid查询 公司名称
     * @param companyUuid
     * @return
     */
    @Query(nativeQuery = true, value = "select c.company_name from tm_company c where c.company_uuid = :company_uuid and del_flag = 0")
    String findCompanyName(@Param(value = "company_uuid") String companyUuid);

    /**
     * 通过公司id查询 公司uuid
     * @param companyId
     * @return
     */
    @Query(nativeQuery = true, value = "select c.company_uuid from tm_company c where c.id = :company_id and del_flag = 0")
    String findCompanyUuid(@Param(value = "company_id") String companyId);
}
